home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / kowin / archive / apl / pedp.lzh / pattern.c < prev    next >
C/C++ Source or Header  |  1996-01-13  |  15KB  |  661 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. #include    <sys_doslib.h>
  7.  
  8. #include "wlib.h"
  9. #include "parts.h"
  10. #include "winop.h"
  11.  
  12. #define    MESSAGE_TABLE_X    32
  13. #define    MESSAGE_TABLE_Y    128
  14. #define    EDIT_RATIO        8
  15. #define    DEFAULT_EDIT    256
  16. #define    TYPE_SOURCE        1
  17. #define    TYPE_INCLUDE    2
  18. #define    max( a, b )        ( (a) > (b) ? (a) : (b) )
  19.  
  20. static    Sheet    Pattern ;
  21. static    Sheet    EditPattern ;
  22. static    ClipClass    PatternClip ;
  23. static    ClipClass    EditPatternClip ;
  24.  
  25. static    char    FileName[100] ;
  26. static    int        Xsize, Ysize ;
  27. static    int        CurrentCode ;
  28. static    int        MessageTableX ;
  29. static    int        ScrollFlag ;
  30. static    int        OutPutType ;
  31. static    WindowID    InputWP ;
  32.  
  33. extern    void    SendUserEvent( WindowID, EventInfo*, Sheet* );
  34.  
  35. /*
  36.     proto -s pattern.c > temp
  37. */
  38. static    int        EventExec( WindowID, EventInfo* );
  39. static    void    EditorClose( WindowID );
  40. static    void    EditorResize( WindowID, int, int, int, int );
  41. static    int        EditExec( WindowID, EventInfo* );
  42. static    int        MessageExec( WindowID, EventInfo* );
  43. static    void    SaveOK( void );
  44. static    int        OKexec( WindowID, EventInfo* );
  45. static    int        GetSize( void );
  46. static    int        PatternRead( Sheet* );
  47. static    void    PatternToEdit( void );
  48. static    void    PatternWrite( void );
  49.  
  50. int    RightCode= 1;
  51.  
  52.  
  53. /*  エディットウインドウのオープン  */
  54. int        PatternOpen( inputwp, name, x, y, oflag, sp )
  55. WindowID    inputwp ;
  56. char    *name ;
  57. int        x, y ;
  58. int        oflag ;
  59. Sheet    *sp ;
  60. {
  61.     int        h, v, sw ;
  62.     char    *p ;
  63.     WindowID    wp, cwp ;
  64.  
  65.     CurrentCode = 0 ;
  66.     InputWP = inputwp ;
  67.     OutPutType = oflag ;
  68.     strcpy( FileName, name );
  69.     strlwr( FileName );
  70.  
  71.     p = strrchr( FileName, '\\' );
  72.     if ( p == NULL )
  73.         FileName[0] = toupper( FileName[0] );
  74.     else
  75.         p[1] = toupper( p[1] );
  76.     if ( strchr( FileName, '.' ) == NULL )
  77.     {
  78.         if ( OutPutType == TYPE_SOURCE )
  79.             strcat( FileName, ".C" );
  80.         else
  81.             strcat( FileName, ".INC" );
  82.     }
  83.  
  84.     if ( sp == NULL )
  85.     {
  86.         if ( GetSize() == FALSE )
  87.         {
  88.             Xsize = x ;
  89.             Ysize = y ;
  90.         }
  91.         if ( Xsize <= 0 && Ysize <= 0 )
  92.         {
  93.             ErrorMessage( "サイズが不正です。", ERROR_OK );
  94.             return( FALSE );
  95.         }
  96.     }
  97.     else
  98.     {
  99.         Xsize = sp->h ;
  100.         Ysize = sp->v ;
  101.     }
  102.  
  103.     if ( PatternRead( sp ) == FALSE )
  104.         return( FALSE );
  105.  
  106.     MessageTableX = max( Xsize+16, MESSAGE_TABLE_X );
  107.     if ( Xsize < 32 && Ysize < 32 )
  108.     {
  109.         h = Xsize * EDIT_RATIO ;
  110.         v = max( Ysize * EDIT_RATIO, MESSAGE_TABLE_Y );
  111.         sw = Close|Push ;
  112.         ScrollFlag = FALSE ;
  113.     }
  114.     else
  115.     {
  116.         h = DEFAULT_EDIT ;
  117.         v = DEFAULT_EDIT ;
  118.         sw = Resize|Close|Push|Zoom ;
  119.         ScrollFlag = TRUE ;
  120.     }
  121.  
  122.     WindowGetPosition( InputWP, &x, &y );
  123.     wp = WindowTitleOpen( x, y, h + MessageTableX, v, NULL, FileName, sw, EventExec );
  124.     if ( ScrollFlag )
  125.     {
  126.         cwp = WindowScrollOpen( 0, 0, h, v, wp, Xsize*EDIT_RATIO, Ysize*EDIT_RATIO,
  127.                                 DirectionX|DirectionY, 16, 16, EditExec );
  128.     }
  129.     else
  130.         cwp = WindowOpen( 0, 0, h, v, wp, EditExec );
  131.     cwp = WindowOpen( h, 0, MessageTableX, v, wp, MessageExec );
  132.     WindowRedraw( wp );
  133.  
  134.     return( TRUE );
  135. }
  136.  
  137. /*  エディットウインドウのイベント処理  */
  138. static    int        EventExec( wp, info )
  139. WindowID    wp ;
  140. EventInfo    *info ;
  141. {
  142.     DrawBuf        buf[1] ;
  143.     WindowID    cwp ;
  144.     int            x, y, size ;
  145.     int            hh, vv ;
  146.     Sheet        *sp ;
  147.     static    ZoomBuffer    zoom ;
  148.  
  149.     switch( info->option )
  150.     {
  151.         case EventOpen :
  152.             ZoomInit( wp, &zoom );
  153.             WindowSetEventAttr( wp, EventAttrDefault|EventUserON );
  154.             return( TRUE );
  155.         case EventRedraw :
  156.             DrawSetClear( buf, 1 );
  157.             WindowDraw( wp, buf, 1 );
  158.             cwp = WindowGetChildTop( wp );
  159.             WindowRedraw( cwp );
  160.             cwp = WindowGetNext( cwp );
  161.             WindowRedraw( cwp );
  162.             return( TRUE );
  163.         case EventClose :
  164.             SaveOK();
  165.             EditorClose( wp );
  166.             return( TRUE );
  167.         case EventZoom :
  168.             ZoomOperation( wp, info );
  169.             return( TRUE );
  170.         case EventResize :
  171.             EditorResize( wp, info->x, info->y, info->h, info->v );
  172.             return( TRUE );
  173.         case EventMouseSwitch :
  174.             if ( info->LeftStat )
  175.             {
  176.                 WindowGetViewSize( wp, &hh, &vv );
  177.                 if ( ScrollFlag && info->x > hh-10 && info->y > vv - 10 )
  178.                 {
  179.                     WindowResizeOperation( wp, info );
  180.                     return( TRUE );
  181.                 }
  182.             }
  183.             cwp = WindowGetChild( wp, info );
  184.             WindowSendEvent( cwp, info );
  185.             return( TRUE );
  186.         case EventKey:
  187.             switch( info->KeyCode ){
  188.             case FuncKeyF(10):
  189.                 PatternWrite();
  190.                 EditorClose( wp );
  191.                 break;
  192.             default:
  193.                 cwp = WindowGetChild( wp, info );
  194.                 WindowSendEvent( cwp, info );
  195.             }
  196.             return    TRUE;
  197.         case EventUser :
  198.             if ( info->ComData == UserSheet )
  199.             {
  200.                 sp = info->ComBuffer ;
  201.                 if ( sp->h == Xsize && sp->v == Ysize )
  202.                 {
  203.                     size =  Pattern.hword * Pattern.v * sizeof( short ) ;
  204.                     memcpy( Pattern.buf1, sp->buf1, size );
  205.                     memcpy( Pattern.buf2, sp->buf2, size );
  206.                     PatternToEdit();
  207.                     WindowRedraw( wp );
  208.                 }
  209.                 return( TRUE );
  210.             }
  211.             return( FALSE );
  212.     }
  213.     return( FALSE );
  214. }
  215.  
  216. /*  エディットウインドウの終了処理  */
  217. static    void    EditorClose( wp )
  218. WindowID    wp ;
  219. {
  220.     int        x, y ;
  221.  
  222.     WindowGetPosition( wp, &x, &y );
  223.     WindowClose( wp );
  224.     MFREE( Pattern.buf1 );
  225.     MFREE( Pattern.buf2 );
  226.     MFREE( EditPattern.buf1 );
  227.     MFREE( EditPattern.buf2 );
  228.     WindowMove( InputWP, x, y );
  229.     WindowSetAttr( InputWP, 0 );
  230. }
  231.  
  232. /*  エディットウインドウのリサイズ処理  */
  233. static    void    EditorResize( wp, x, y, h, v )
  234. WindowID    wp ;
  235. int            x, y, h, v ;
  236. {
  237.     int        ch, cv, vh, vv, maxh, maxv ;
  238.     WindowID    cwp ;
  239.  
  240.     cwp = WindowGetChildBottom( wp );
  241.     WindowGetViewSize( cwp, &vh, &vv );
  242.     WindowGetSize( cwp, &ch, &cv );
  243.     maxh = Xsize * EDIT_RATIO + ch - vh + MessageTableX ;
  244.     maxv = Ysize * EDIT_RATIO + cv - vv ;
  245.     if ( h > maxh )
  246.         h = maxh ;
  247.     if ( v > maxv )
  248.         v = maxv ;
  249.  
  250.     cwp = WindowGetChildTop( wp );
  251.     WindowResize( cwp, h - MessageTableX, 0, MessageTableX, v );
  252.     cwp = WindowGetNext( cwp );
  253.     WindowResize( cwp, 0, 0, h - MessageTableX, v );
  254.     WindowResize( wp, x, y, h, v );
  255. }
  256.  
  257. /*    エディットウインドウのイベント処理  */
  258. static    int        EditExec( wp, info )
  259. WindowID    wp ;
  260. EventInfo    *info ;
  261. {
  262.     WindowID    cwp ;
  263.     int        i, code, x, y, x2, y2 ;
  264.     DrawBuf    buf[2] ;
  265.  
  266.     switch( info->option )
  267.     {
  268.         case EventRedraw :
  269.             DrawSetClear( buf, 1 );
  270.             DrawSetPut( buf+1, 0, 0, &EditPattern );
  271.             WindowDraw( wp, buf, 2 );
  272.             return( TRUE );
  273.         case EventKey:
  274.             switch( info->KeyCode ){
  275.             case 0x1b:
  276.             case '0': code= 0; goto    _Dot;
  277.             case '1': code= 1; goto    _Dot;
  278.             case '2': code= 2; goto    _Dot;
  279.             case '3': code= 3; goto    _Dot;
  280.             case ' ': code= CurrentCode; goto    _Dot;
  281.             }
  282.             return    TRUE;
  283.         case EventMouseSwitch :
  284.             if ( info->LeftStat )
  285.                 code = CurrentCode ;
  286.             else if ( info->RightStat )
  287.                 code = RightCode ;
  288.             else
  289.                 return( TRUE );
  290.         _Dot:
  291.             x = info->x / EDIT_RATIO ;
  292.             y = info->y / EDIT_RATIO ;
  293.             if ( 0 <= x && x < Xsize && 0 <= y && y < Ysize )
  294.             {
  295.                 SheetLine( &Pattern, &PatternClip, x, y, x, y, code, OptionFill );
  296.                 DrawSetLine( buf, 8+x, 110+y, 8+x, 110+y, code, OptionFill );
  297.                 cwp = WindowGetLast( wp );
  298.                 WindowDraw( cwp, buf, 1 );
  299.  
  300.                 x *= EDIT_RATIO ;
  301.                 y *= EDIT_RATIO ;
  302.                 x2 = x + EDIT_RATIO - 1 ;
  303.                 y2 = y + EDIT_RATIO - 1 ;
  304.                 DrawSetLine( buf, x, y, x2, y2, code, OptionFill );
  305.                 SheetLine( &EditPattern, &EditPatternClip, x, y, x2, y2,
  306.                             code, OptionFill );
  307.                 WindowDraw( wp, buf, 1 );
  308.             }
  309.             return( TRUE );
  310.     }
  311.     return( FALSE );
  312. }
  313.  
  314. /*  メッセージウインドウのイベント処理  */
  315. static    int        MessageExec( wp, info )
  316. WindowID    wp ;
  317. EventInfo    *info ;
  318. {
  319.     int        i, x, y ;
  320.     DrawBuf    dbuf[2] ;
  321.     static    DrawBuf    *bufp, buf[28] ;
  322.     static    ClipClass    clip[3] ;
  323.     static    char        *msg[3] = { "SAVE", "QUIT", "MOVE" } ;
  324.  
  325.     switch( info->option )
  326.     {
  327.         case EventOpen :
  328.             bufp = buf ;
  329.             DrawSetClear( bufp++, 1 );
  330.             for( i = 0 ; i < 4 ; ++i )
  331.             {
  332.                 DrawSetLine( bufp++, 4, i*12+4, 4+24, i*12+4+11, i, OptionFill );
  333.                 if ( i == CurrentCode )
  334.                     DrawSetLine( bufp++, 4, i*12+4, 4+11, i*12+4+11, ShadowDown, OptionShadow );
  335.                 else
  336.                     DrawSetLine( bufp++, 4, i*12+4, 4+11, i*12+4+11, ShadowUp, OptionShadow );
  337.                 if ( i == RightCode )
  338.                     DrawSetLine( bufp++, 4+12, i*12+4, 4+24, i*12+4+11, ShadowDown, OptionShadow );
  339.                 else
  340.                     DrawSetLine( bufp++, 4+12, i*12+4, 4+24, i*12+4+11, ShadowUp, OptionShadow );
  341.             }
  342.             for( i = 0 ; i < 3 ; ++i )
  343.             {
  344.                 DrawSetSymbol( bufp++, 4, 60+14*i, msg[i], AttrDefault, 12 );
  345.                 DrawSetLine( bufp++, 3, 59+14*i, 4+24, 60+14*i+12, ShadowUp, OptionShadow );
  346.                 ClipSet( &clip[i], 4, 60+14*i, 24, 12 );
  347.             }
  348.             DrawSetLine( bufp++, 7, 109, 8+Xsize, 110+Ysize, ShadowDown, OptionShadow );
  349.             DrawSetPut( bufp++, 8, 110, &Pattern );
  350.             return( TRUE );
  351.         case EventRedraw :
  352.             WindowDraw( wp, buf, bufp-buf );
  353.             return( TRUE );
  354.         case EventMouseSwitch :
  355.             if ( ClipInner( &clip[0], info->x, info->y ) )
  356.             {
  357.                 PatternWrite();
  358.                 EditorClose( WindowGetParent( wp ) );
  359.             }
  360.             else if ( ClipInner( &clip[1], info->x, info->y ) )
  361.             {
  362.                 EditorClose( WindowGetParent( wp ) );
  363.             }
  364.             else if ( ClipInner( &clip[2], info->x, info->y ) )
  365.             {
  366.                 SendUserEvent( WindowGetParent( wp ), info, &Pattern );
  367.             }
  368.             else
  369.             {
  370.                 y = ( info->y - 4 ) / 12 ;
  371.                 if ( 0 <= y && y < 4 )
  372.                 {
  373.                     if( info->LeftStat ){
  374.                         DrawSetLine( dbuf, 4, CurrentCode*12+4, 4+11, CurrentCode*12+4+11,
  375.                                     ShadowUp, OptionShadow );
  376.                         CurrentCode = y ;
  377.                         DrawSetLine( dbuf+1, 4, CurrentCode*12+4, 4+11, CurrentCode*12+4+11,
  378.                                     ShadowDown, OptionShadow );
  379.                         WindowDraw( wp, dbuf, 2 );
  380.                     }else if( info->RightStat ){
  381.                         DrawSetLine( dbuf, 4+12, RightCode*12+4, 4+24, RightCode*12+4+11,
  382.                                     ShadowUp, OptionShadow );
  383.                         RightCode = y ;
  384.                         DrawSetLine( dbuf+1, 4+12, RightCode*12+4, 4+24, RightCode*12+4+11,
  385.                                     ShadowDown, OptionShadow );
  386.                         WindowDraw( wp, dbuf, 2 );
  387.                     }
  388.                 }
  389.             }
  390.             return( TRUE );
  391.     }
  392.     return( FALSE );
  393. }
  394.  
  395. static    void    SaveOK()
  396. {
  397.     EventInfo    Info ;
  398.     WindowID    wp ;
  399.     ClipClass    yes, no ;
  400.     int        hx, hy ;
  401.  
  402.     WindowGetRootScroll( &hx, &hy );
  403.     wp = WindowSimpleOpen( hx+234, hy+200, 300, 80, NULL, OKexec );
  404.     WindowRedraw( wp );
  405.  
  406.     ClipSet( &yes, 60-30, 50-4, 60, 24 );
  407.     ClipSet( &no, 240-30, 50-4, 60, 24 );
  408.  
  409.     for(;;)
  410.     {
  411.         WindowGetEventInfo( &Info );
  412.         if ( Info.LeftStat && WindowGetChild( WindowRootID, &Info ) == wp )
  413.         {
  414.             if ( ClipInner( &yes, Info.x, Info.y ) )
  415.             {
  416.                 WindowClose( wp );
  417.                 PatternWrite();
  418.                 return ;
  419.             }
  420.             if ( ClipInner( &no, Info.x, Info.y ) )
  421.             {
  422.                 WindowClose( wp );
  423.                 return ;
  424.             }
  425.         }else if( Info.option == EventKey ){
  426.             switch( Info.KeyCode ){
  427.             case 'y':
  428.             case 'Y':
  429.                 WindowClose( wp );
  430.                 PatternWrite();
  431.                 return;
  432.             case 'n':
  433.             case 'N':
  434.                 WindowClose( wp );
  435.                 return;
  436.             }
  437.         }
  438.     }
  439. }
  440.  
  441. static    int        OKexec( wp, info )
  442. WindowID    wp ;
  443. EventInfo    *info ;
  444. {
  445.     DrawBuf        buf[10] ;
  446.  
  447.     switch( info->option )
  448.     {
  449.         case EventRedraw :
  450.             DrawSetClear( buf, 1 );
  451.             DrawSetSymbol( buf+1, 30, 10, "パターンデータを保存しますか?", AttrDefault, 16 );
  452.             DrawSetSymbol( buf+2, 60-24, 50, "YES", AttrDefault, 16 );
  453.             DrawSetSymbol( buf+3, 240-16, 50, "NO", AttrDefault, 16 );
  454.             DrawSetLine( buf+4, 60-30, 50-4, 60+30, 50+20, ShadowUp, OptionShadow );
  455.             DrawSetLine( buf+5, 240-30, 50-4, 240+30, 50+20, ShadowUp, OptionShadow );
  456.             WindowDraw( wp, buf, 6 );
  457.             return( TRUE );
  458.     }
  459.     return( FALSE );
  460. }
  461.  
  462. static    int        GetSize()
  463. {
  464.     FILE    *fp ;
  465.     char    buf[50] ;
  466.  
  467.     fp = fopen( FileName, "r" );
  468.     if ( fp == NULL )
  469.         return( FALSE );
  470.  
  471.     do
  472.     {
  473.         if ( fscanf( fp, "%s", buf ) == 0 )
  474.             return( FALSE );
  475.     }
  476.     while( strcmp( buf, "Sheet" ) != 0 );
  477.  
  478.     fscanf( fp, "%s", buf );    /*  Pattern Name  */
  479.  
  480.     fscanf( fp, "= {%d,", &Xsize );
  481.     fscanf( fp, "%d", &Ysize );
  482.  
  483.     fclose( fp );
  484.     if ( Xsize > 0 && Ysize > 0 )
  485.         return( TRUE );
  486.     else
  487.     {
  488.         ErrorMessage( "ファイルの構造が不正です。", ERROR_OK );
  489.         return( FALSE );
  490.     }
  491. }
  492.  
  493. /*  パターンの読み込み  */
  494. static    int        PatternRead( sp )
  495. Sheet    *sp ;
  496. {
  497.     int        i, n, editsize, size ;
  498.     short    *p ;
  499.     char    buf[100] ;
  500.     FILE    *fp ;
  501.  
  502.     Pattern.h = Xsize ;
  503.     Pattern.v = Ysize ;
  504.     Pattern.hword = ( Xsize - 1 ) / 16 + 1 ;
  505.     size =  Pattern.hword * Pattern.v * sizeof( short ) ;
  506.     Pattern.buf1 = MALLOC( size );
  507.     Pattern.buf2 = MALLOC( size );
  508.     ClipSet( &PatternClip, 0, 0, Xsize, Ysize );
  509.  
  510.     EditPattern.h = Xsize * 8 ;
  511.     EditPattern.v = Ysize * 8 ;
  512.     EditPattern.hword = ( Xsize * 8 - 1 ) / 16 + 1 ;
  513.     editsize =  EditPattern.hword * EditPattern.v * sizeof( short ) ;
  514.     EditPattern.buf1 = MALLOC( editsize );
  515.     EditPattern.buf2 = MALLOC( editsize );
  516.     ClipSet( &EditPatternClip, 0, 0, Xsize*8, Ysize*8 );
  517.  
  518.     if ( EditPattern.buf2 > 0x80000000 )
  519.     {
  520.         ErrorMessage( "メモリが足りません。", ERROR_OK );
  521.         return( FALSE );
  522.     }
  523.  
  524.     if ( sp != NULL )
  525.     {
  526.         memcpy( Pattern.buf1, sp->buf1, size );
  527.         memcpy( Pattern.buf2, sp->buf2, size );
  528.         PatternToEdit();
  529.         return( TRUE );
  530.     }
  531.  
  532.     fp = fopen( FileName, "r" );
  533.     if ( fp == NULL )
  534.     {
  535.         memset( Pattern.buf1, 0xFF, size );
  536.         memset( Pattern.buf2, 0x00, size );
  537.         memset( EditPattern.buf1, 0xFF, editsize );
  538.         memset( EditPattern.buf2, 0x00, editsize );
  539.         return( TRUE );
  540.     }
  541.  
  542.     size /= sizeof( short );
  543.     do
  544.     {
  545.         fgets( buf, 80, fp );
  546.     }
  547.     while( strncmp( buf, "static", 6 ) != 0 );
  548.  
  549.     p = Pattern.buf1 ;
  550.     for( i = 0 ; i < size ; ++i )
  551.     {
  552.         fscanf( fp, "0x%X, ", &n );
  553.         *p++ = n ;
  554.     }
  555.  
  556.     do
  557.     {
  558.         fgets( buf, 80, fp );
  559.     }
  560.     while( strncmp( buf, "static", 6 ) != 0 );
  561.  
  562.     p = Pattern.buf2 ;
  563.     for( i = 0 ; i < size ; ++i )
  564.     {
  565.         fscanf( fp, "0x%X, ", &n );
  566.         *p++ = n ;
  567.     }
  568.     fclose( fp );
  569.  
  570.     PatternToEdit();
  571.     return( TRUE );
  572. }
  573.  
  574. static    void    PatternToEdit()
  575. {
  576.     int        x, y, code, bit ;
  577.     short    *p1, *p2 ;
  578.  
  579.     p1 = Pattern.buf1 ;
  580.     p2 = Pattern.buf2 ;
  581.     for( y = 0 ; y < Ysize ; ++y )
  582.     {
  583.         for( x = 0 ; x < Xsize ; ++x )
  584.         {
  585.             bit = x % 16 ;
  586.             code = 0 ;
  587.             if ( *p1 & ( 0x8000 >> bit ) )
  588.                 code += 1 ;
  589.             if ( *p2 & ( 0x8000 >> bit ) )
  590.                 code += 2 ;
  591.             SheetLine( &EditPattern, &EditPatternClip, x*8, y*8, x*8+7, y*8+7,
  592.                         code, OptionFill );
  593.             if ( bit == 15 )
  594.             {
  595.                 p1++ ;
  596.                 p2++ ;
  597.             }
  598.         }
  599.         if ( x % 16 )
  600.         {
  601.             p1++ ;
  602.             p2++ ;
  603.         }
  604.     }
  605. }
  606.  
  607. static    void    PatternWrite()
  608. {
  609.     int        i, size ;
  610.     FILE    *fp ;
  611.     char    *cp, *name ;
  612.     unsigned    short    *p ;
  613.  
  614.     size =  Pattern.hword * Pattern.v ;
  615.  
  616.     fp = fopen( FileName, "w" );
  617.     if ( fp == NULL )
  618.     {
  619.         ErrorMessage( "ファイルが出力できません。", ERROR_OK );
  620.         return ;
  621.     }
  622.     cp = strchr( FileName, '.' );
  623.     if ( cp != NULL )
  624.         *cp = '\0' ;
  625.     name = strrchr( FileName, '\\' );
  626.     if ( name == NULL )
  627.         name = FileName ;
  628.     else
  629.         name ++ ;
  630.  
  631.     if ( OutPutType == TYPE_SOURCE )
  632.         fprintf( fp, "#include \"wlib.h\"\n\n" );
  633.     else
  634.     {
  635.         fprintf( fp, "#ifndef CLASS\n" );
  636.         fprintf( fp, "#define CLASS static\n" );
  637.         fprintf( fp, "#endif\n" );
  638.     }
  639.  
  640.     p = Pattern.buf1 ;
  641.     fprintf( fp, "static\tshort\t%s1[] = {\n", name );
  642.     fprintf( fp, "\t0x%04X", *p++ );
  643.     for( i = 1 ; i < size ; ++i )
  644.         fprintf( fp, ", 0x%04X", *p++ );
  645.     fprintf( fp, "\n};\n" );
  646.  
  647.     p = Pattern.buf2 ;
  648.     fprintf( fp, "static\tshort\t%s2[] = {\n", name );
  649.     fprintf( fp, "\t0x%04X", *p++ );
  650.     for( i = 1 ; i < size ; ++i )
  651.         fprintf( fp, ", 0x%04X", *p++ );
  652.     fprintf( fp, "\n};\n" );
  653.  
  654.     if ( OutPutType == TYPE_INCLUDE )
  655.         fprintf( fp, "CLASS\t" );
  656.  
  657.     fprintf( fp, "Sheet\t%sPattern = { %d, %d, %d, %s1, %s2 };\n",
  658.                 name, Pattern.h, Pattern.v, Pattern.hword, name, name );
  659.     fclose( fp );
  660. }
  661.